#include<stdio.h>
#include<sys/types.h>
#include<unistd.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<stdlib.h>
int main(int argc, char *argv[])
{
    int fileo,fileo1,filew,filer,len,len1;
    char *buf;
    fileo=open(argv[1],O_RDONLY,00644);
    if(fileo==-1)
    {
        perror("cannot open/creat file");
        exit(0);
    }
    fileo1=open(argv[2],O_RDWR|O_APPEND|O_CREAT,00644);
    if(fileo1==-1)
    {
        perror("cannot open/creat file");
        exit(0);
    }
    lseek(fileo,0,SEEK_SET);
    struct stat buffer,buffer1;
    fstat(fileo,&buffer);
    len=buffer.st_size;
    //buf=(malloc(fileo));//没必要一次把大文件的len读到内存
    fstat(fileo1,&buffer1);
    len1=buffer1.st_size;
        filer=read(fileo,buf,1);
    while(filer!=0)
    {
        filer=read(fileo,buf,1);
            // if(filer==0)
              //   perror("end of file");
            //else if(filer==-1)
              //  perror("cannot read");
           /* else
                 printf("read success");*/
        filew=write(fileo1,buf,1);
        //if(filew==-1)
        //{
          //  perror("cannot write");
            //exit(0);
        // }
        /*else
            printf("\t copy success\n");*/
    }
    printf("\n\t\t\t\tAll Done\n\n");
}
